package com.tanhua.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.dubbo.mappers.SettingsMapper;
import com.tanhua.model.domain.Settings;
import com.tanhua.service.SettingsApi;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class SettingsApiImpl implements SettingsApi {

    @Autowired
    private SettingsMapper settingsMapper;

    /**
     * 根据用户id进行查询通知设置
     * @param id  用户id
     * @return
     */
    @Override
    public Settings getByUserId(Long id) {
        QueryWrapper qw = new QueryWrapper();
        qw.eq("user_id", id);
        Settings settings = settingsMapper.selectOne(qw);
        return settings;
    }

    /**
     * 修改用户的通知设置
     * @param settings 用户需要修改成的通知设置
     */
    @Override
    public void update(Settings settings) {
        QueryWrapper qw = new QueryWrapper();
        qw.eq("user_id", settings.getUserId());
        settingsMapper.update(settings, qw);
    }

    /**
     * 保存用户通知设置
     * @param settings 用户第一次需要设置的通知设置
     */
    @Override
    public void save(Settings settings) {
        settingsMapper.insert(settings);
    }
}